<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function login(){
        if($_COOKIE['status']=="1"){
            $this->redirect('index', array('status' => "1"));
        }else{
            $this->display("login");
        }
    }
    public function register(){
        $this->display();
    }
    public function register2(){
        $name=I("post.name");
        $password=I("post.password");
        $data=M("user")->where("name = '$name'")->select();
        if(empty($data)){
            $list['name'] = "$name";
            $list['user_password'] = "$password";
            if(M("user")->data($list)->add()){
                echo "sucess";
            }else{
                echo "ukownError";
            }
        }else{
            echo "error";
        }
    }
    public function register3(){
        $news=I("get.news");
        if($news=="sucess"){
            $this->assign("news","注册成功！");
        }else{
            $this->assign("news","注册失败！");
        }
        $this->display();
    }
    public function login2(){
        $name=I("post.name");
        $password=I("post.password");
        $data=M("user")->where("name = '$name'")->find();
        if(!empty($data["user_password"])&&$data["user_password"]==$password){
            echo "right";
            cookie('status',"1");
            cookie('user',"$name");
            cookie('psw',"$password");
        }else{
            echo "wrong";
        }
    }
    //登录之后显示的主页面
    public function index($status=null){
        if($status!=1){
            $this->login();
        }elseif($status==1){
            $this->display();
        }
    }

    public function cleaningClassification(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function qingxibaojie(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function childrenManagement(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function maternalAndInfantServices(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function repair(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function professionalEscort(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function my(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }else{
            $name=$_COOKIE["user"];
            $map['name']=$name;
            $data=M("User")->where($map)->find();
            $this->assign("data",$data);
            $this->display();
        }
    }
    public function lifeFirstAidKit(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function  jiazhengindex(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function  staffBrowsing(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }else{
            $data=M("emp")->select();
            $this->assign("data",$data);
            $this->display();
        }
    }
    public function  order(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }else{
            $map['user_name']=$_COOKIE['user'];
            $data=M("oder")->where($map)->select();
            $this->assign("data",$data);
            $this->display();
        }
    }
    public function  mine(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }else{
            $name=$_COOKIE["user"];
            $map['name']=$name;
            $data=M("User")->where($map)->find();
            $this->assign("data",$data);
            $this->display();
        }
    }
    public function changePassword(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }else{
            $this->assign("name",$_COOKIE['name']);
            $this->assign("psw",$_COOKIE['psw']);
            $this->display();
        }
    }
    public function  check(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    //我的，切换账号
    public function  swit(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    //退出登录
    public function login_out(){
        cookie("status",0);
        $this->login();
    }

    //修改密码
    public function change(){
        $pas=$_GET['npsw'];
        $map['name']=$_COOKIE['user'];
        $data['user_password']=$pas;
        M("User")->where($map)->save($data);
        cookie("psw",$pas);
        $this->redirect("my");
    }
    public function personalProfile(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }else{
            $map['emp_name']=$_GET["name"];
            $data=M("emp")->where($map)->find();
            $this->assign("data",$data);
            $this->display();
        }
    }
    public function lists(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function information(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function found(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function development(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function productIntroduction(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function advantage(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function core(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function appointment(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function pay(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
    public function appointmentSuccess(){
        if($_COOKIE["status"]!=1){
            $this->login();
        }
        $this->display();
    }
}